<?php

defined( 'IN_CLASS' ) or die( 'Access Error!' );

/**
 * 全局变量类
 */
class all {
	
	public static $cfg = array();
	public static $aU = array();
	public static $aOut = array();
	
	public static function setcfg( $cfg ) {
		self::$cfg = array_merge( self::$cfg, $cfg );
	}
}

/**
 * model 创建类
 */
class model {
	private static $model;
	
	/**
	 * 用户操作数据库
	 *
	 * @return DataBase
	 */
	public static function dbuser() {
		if( !isset( self::$model['dbuser'] ) || !is_object( self::$model['dbuser'] ) ){
		 	include_once DIR_LIB . 'class.db.php';
		 	self::$model['dbuser'] = new DataBase( all::$cfg['db'] );
		}
		return self::$model['dbuser'];
	}
	
	/**
	 * 评论操作数据库
	 *
	 * @return DataBase
	 */
	public function dbcomment() {
		if( !isset( self::$model['dbcomment'] ) || !is_object( self::$model['dbcomment'] ) ){
		 	include_once DIR_LIB . 'class.db.php';
		 	self::$model['dbcomment'] = new DataBase( all::$cfg['db'] );
		}
		return self::$model['dbcomment'];
	}
	
	/**
	 * 图片操作数据库
	 *
	 * @return DataBase
	 */
	public function dbpix() {
		if( !isset( self::$model['dbpix'] ) || !is_object( self::$model['dbpix'] ) ) {
		 	include_once DIR_LIB . 'class.db.php';
		 	self::$model['dbpix'] = new DataBase( all::$cfg['db'] );
		}
		return self::$model['dbpix'];
	}
	
	/**
	 * 会员操作模型model
	 *
	 * @return ModelMember
	 */
	public static function member() {
		if( !isset( self::$model['member'] ) || !self::$model['member'] ) {
			include_once DIR_MDL . 'member.php';
			self::$model['member'] = new ModelMember();
		}
		return self::$model['member'];
	}
	
	/**
	 * 积分操作模型model 
	 *
	 * @return ModelScore
	 */
	public static function score() {
		if( !isset( self::$model['score'] ) || !self::$model['score'] ) {
			include_once DIR_MDL . 'score.php';
			self::$model['score'] = new ModelScore();
		}
		return self::$model['score'];
	}
	
	/**
	 * 小纸条操作模型model
	 *
	 * @return ModelSms
	 */
	public static function sms() {
		if( !isset( self::$model['sms'] ) || !self::$model['sms'] ) {
			include_once DIR_MDL . 'sms.php';
			self::$model['sms'] = new ModelSms();
		}
		return self::$model['sms'];
	}
	
	/**
	 * 留言操作模型model
	 *
	 * @return ModelWord
	 */
	public static function word() {
		if( !isset( self::$model['word'] ) || !self::$model['word'] ) {
			include_once DIR_MDL . 'word.php';
			self::$model['word'] = new ModelWord();
		}
		return self::$model['word'];
	}
	
	/**
	 * 相册操作模型model
	 *
	 * @return ModelPic
	 */
	public static function pic() {
		if( !isset( self::$model['pic'] ) || !self::$model['pic'] ) {
			include_once DIR_MDL . 'pic.php';
			self::$model['pic'] = new ModelPic();
		}
		return self::$model['pic'];
	}
	
	/**
	 * 共享文件操作模型model
	 *
	 * @return ModelShare
	 */
	public static function share() {
		if( !isset( self::$model['share'] ) || !self::$model['share'] ) {
			include_once DIR_MDL . 'share.php';
			self::$model['share'] = new ModelShare();
		}
		return self::$model['share'];
	}
	
	/**
	 * 评论操作模型model
	 *
	 * @return ModelComment
	 */
	public static function comment() {
		if( !isset( self::$model['comment'] ) || !self::$model['comment'] ) {
			include_once DIR_MDL . 'comment.php';
			self::$model['comment'] = new ModelComment();
		}
		return self::$model['comment'];
	}
	
	/**
	 * 在线表操作模型model
	 *
	 * @return ModelOnline
	 */
	public static function online() {
		if( !isset( self::$model['online'] ) || !self::$model['online'] ) {
			include_once DIR_MDL . 'online.php';
			self::$model['online'] = new ModelOnline();
		}
		return self::$model['online'];
	}
	
	/**
	 * 链接操作模型model
	 *
	 * @return ModelLinks
	 */
	public static function links() {
		if( !isset( self::$model['links'] ) || !self::$model['links'] ) {
			include_once DIR_MDL . 'links.php';
			self::$model['links'] = new ModelLinks();
		}
		return self::$model['links'];
	}
}